const { Sequelize } = require("sequelize");
require("dotenv").config();

const sequelize = new Sequelize({
  dialect: "mysql",
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  username: process.env.DB_USERNAME,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_DATABASE,
  logging: false, // 关闭SQL日志（可选）
});

(async () => {
  try {
    await sequelize.sync(); // 生产环境需去掉 force{force: true}
    // await sequelize.sync({ force: true });
    console.log('Database synchronized');
  } catch (error) {
    console.error('Database sync failed:', error);
  }
})();

module.exports = sequelize;
